/**
 * @description cnode api 访问
 * @author anytao
 * @created 2016-08-24
 * @version 1.0
 */

'use strict';

import request from 'request';

export default class extends think.service.base {

   async  getTopics(page, tab, limit) {
       
        let url = 'https://cnodejs.org/api/v1/topics?mdrender=false&page=' + page + '&limit=' + limit;

        let getTopic = (url) => {

            let deferred = think.defer();
            request({
                url: url
            }, function(err, response, body) {
                if (err) {
                    deferred.reject(err);
                } else {
                    deferred.resolve(body);
                }
            });
            return deferred.promise;
        }

        return await getTopic(url);
    }
}